package com.gz.mapper;

import com.gz.entity.Monster;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface MonsterMapperAnnotation {
    //注解方式

    //添加monster
    @Insert("insert into `monster` (`age`,`birthday`,`email`,`gender`,`name`,`salary`) " +
            "values (#{age},#{birthday},#{email},#{gender},#{name},#{salary})")
    /**
     * 1.useGeneratedKeys = true 返回自增的值
     * 2.keyProperty = "id" 自增值对应的对象(Monster)属性
     * 3.keyColumn = "id" 自增值对应的表的字段
     * 4.如果keyProperty和keyColumn一样，可以只写keyProperty
     */
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    public void addMonster(Monster monster);

    //根据id删除
    @Delete("delete from `monster` where id = #{id}")
    public void delMonster(int monsterId);

    //修改Monster
    @Update("update monster set age=#{age},birthday=#{birthday},email=#{email}, " +
            "gender=#{gender},name=#{name},salary=#{salary} where id = #{id}")
    public void updateMonster(Monster monster);

    //查询-根据id
    @Select("select * from monster where id=#{id}")
    public Monster getMonsterById(Integer id);

    //查询所有Monster
    @Select("select * from monster")
    public List<Monster> getMonsters();
}
